import { createRouter, createWebHistory } from 'vue-router'
import { userInfoState } from '@/stores/store'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      name: '登陆页',
      meta: {
        isShow: false
      },
      component: () => import('../views/LoginView.vue')
    },
    {
      path: '/',
      name: '首页',
      component: () => import('../views/HomeView.vue'),
      meta: {
        isShow: false
      },
      children: [
        {
          path: "/over/view",
          name: "数据概览",
          meta: {
            isShow: true
          },
          component: () => import('@/components/pages/HomeData.vue')
        }
      ]
    },
    {
      path: '/sys',
      name: '系统管理',
      component: () => import('../views/HomeView.vue'),
      meta: {
        isShow: true
      },
      children: [
        {
          path: '/sys/user/manage',
          name: '用户管理',
          meta: {
            isShow: true,
            code: "user"
          },
          component: () => import('@/components/pages/UserManage.vue')
        },
        {
          path: '/sys/role/manage',
          name: '角色管理',
          meta: {
            isShow: true,
            code: "role"
          },
          component: () => import('@/components/pages/RoleManage.vue')
        }

      ]
    }
  ]
})

router.beforeEach((to) => {
  if (to.path != "/login" && !userInfoState().isLogin()) {
    return "/login"
  }
})


export default router